/*模拟数据接口*/

export interface Product {
    id:number,
    title:string,
    price:number,
    inventory:number // 库存
}

const products:Product[] = [
    {id:1,title:'iPhone14 pro',price:7999,inventory:2},
    {id:2,title:'Macbook Air',price:9499,inventory:2},
    {id:3,title:'Macbook Pro',price:14999,inventory:2},
]

export const getProducts = async () => {
    await wait(500)
    return products
}

export const buyProduct = async () => {
    await await(500)
    return Math.random() > 0.5
}

function wait(delay:number){
    return new Promise((resolve,reject) => {
        setTimeout(resolve,delay)
    })
}
